home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / webserver / iis / upload.inc < prev    next >
Text File  |  2005-02-12  |  6KB  |  185 lines

  1. <SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
  2. Const IncludeType = 2 
  3. Dim UploadSizeLimit
  4. Function GetUpload()
  5. Dim Result
  6. Set Result = Nothing
  7. If Request.ServerVariables("REQUEST_METHOD") = "POST" Then 
  8. Dim CT, PosB, Boundary, Length, PosE
  9. CT = Request.ServerVariables("HTTP_Content_Type") 
  10. If LCase(Left(CT, 19)) = "multipart/form-data" Then 
  11. PosB = InStr(LCase(CT), "boundary=") 
  12. If PosB > 0 Then Boundary = Mid(CT, PosB + 9) 
  13. PosB = InStr(LCase(CT), "boundary=") 
  14. If PosB > 0 then 
  15. PosB = InStr(Boundary, ",")
  16. If PosB > 0 Then Boundary = Left(Boundary, PosB - 1)
  17. end if
  18. Length = CLng(Request.ServerVariables("HTTP_Content_Length")) 
  19. If "" & UploadSizeLimit <> "" Then
  20. UploadSizeLimit = CLng(UploadSizeLimit)
  21. If Length > UploadSizeLimit Then
  22. Request.BinaryRead (Length)
  23. Err.Raise 2, "GetUpload", "Upload size " & FormatNumber(Length, 0) & "B exceeds limit of " & FormatNumber(UploadSizeLimit, 0) & "B"
  24. Exit Function
  25. End If
  26. End If
  27. If Length > 0 And Boundary <> "" Then 
  28. Boundary = "--" & Boundary
  29. Dim Head, Binary
  30. Binary = Request.BinaryRead(Length) 
  31. Set Result = SeparateFields(Binary, Boundary)
  32. Binary = Empty 
  33. Else
  34. Err.Raise 10, "GetUpload", "Zero length request ."
  35. End If
  36. Else
  37. Err.Raise 11, "GetUpload", "No file sent."
  38. End If
  39. Else
  40. Err.Raise 1, "GetUpload", "Bad request method."
  41. End If
  42. Set GetUpload = Result
  43. End Function
  44. Function SeparateFields(Binary, Boundary)
  45. Dim PosOpenBoundary, PosCloseBoundary, PosEndOfHeader, isLastBoundary
  46. Dim Fields
  47. Boundary = StringToBinary(Boundary)
  48. PosOpenBoundary = InStrB(Binary, Boundary)
  49. PosCloseBoundary = InStrB(PosOpenBoundary + LenB(Boundary), Binary, Boundary, 0)
  50. Set Fields = CreateObject("Scripting.Dictionary")
  51. Do While (PosOpenBoundary > 0 And PosCloseBoundary > 0 And Not isLastBoundary)
  52. Dim HeaderContent, FieldContent, bFieldContent
  53. Dim Content_Disposition, FormFieldName, SourceFileName, Content_Type
  54. Dim Field, TwoCharsAfterEndBoundary
  55. PosEndOfHeader = InStrB(PosOpenBoundary + Len(Boundary), Binary, StringToBinary(vbCrLf + vbCrLf))
  56. HeaderContent = MidB(Binary, PosOpenBoundary + LenB(Boundary) + 2, PosEndOfHeader - PosOpenBoundary - LenB(Boundary) - 2)
  57. bFieldContent = MidB(Binary, (PosEndOfHeader + 4), PosCloseBoundary - (PosEndOfHeader + 4) - 2)
  58. GetHeadFields BinaryToString(HeaderContent), Content_Disposition, FormFieldName, SourceFileName, Content_Type
  59. Set Field = CreateUploadField() 
  60. Set FieldContent = CreateBinaryData()
  61. FieldContent.ByteArray = bFieldContent
  62. FieldContent.Length = LenB(bFieldContent)
  63. Field.Name = FormFieldName
  64. Field.ContentDisposition = Content_Disposition
  65. Field.FilePath = SourceFileName
  66. Field.FileName = GetFileName(SourceFileName)
  67. Field.ContentType = Content_Type
  68. Field.Length = FieldContent.Length
  69. Set Field.Value = FieldContent
  70. Fields.Add FormFieldName, Field
  71. TwoCharsAfterEndBoundary = BinaryToString(MidB(Binary, PosCloseBoundary + LenB(Boundary), 2))
  72. isLastBoundary = TwoCharsAfterEndBoundary = "--"
  73. If Not isLastBoundary Then 
  74. PosOpenBoundary = PosCloseBoundary
  75. PosCloseBoundary = InStrB(PosOpenBoundary + LenB(Boundary), Binary, Boundary)
  76. End If
  77. Loop
  78. Set SeparateFields = Fields
  79. End Function
  80. Function GetHeadFields(ByVal Head, Content_Disposition, Name, FileName, Content_Type)
  81. Content_Disposition = LTrim(SeparateField(Head, "content-disposition:", ";"))
  82. Name = (SeparateField(Head, "name=", ";")) 
  83. If Left(Name, 1) = """" Then Name = Mid(Name, 2, Len(Name) - 2)
  84. FileName = (SeparateField(Head, "filename=", ";")) 
  85. If Left(FileName, 1) = """" Then FileName = Mid(FileName, 2, Len(FileName) - 2)
  86. Content_Type = LTrim(SeparateField(Head, "content-type:", ";"))
  87. End Function
  88. Function SeparateField(From, ByVal sStart, ByVal sEnd)
  89. Dim PosB, PosE, sFrom
  90. sFrom = LCase(From)
  91. PosB = InStr(sFrom, sStart)
  92. If PosB > 0 Then
  93. PosB = PosB + Len(sStart)
  94. PosE = InStr(PosB, sFrom, sEnd)
  95. If PosE = 0 Then PosE = InStr(PosB, sFrom, vbCrLf)
  96. If PosE = 0 Then PosE = Len(sFrom) + 1
  97. SeparateField = Mid(From, PosB, PosE - PosB)
  98. Else
  99. SeparateField = Empty
  100. End If
  101. End Function
  102. Function GetFileName(FullPath)
  103. Dim Pos, PosF
  104. PosF = 0
  105. For Pos = Len(FullPath) To 1 Step -1
  106. Select Case Mid(FullPath, Pos, 1)
  107. Case "/", "\": PosF = Pos + 1: Pos = 0
  108. End Select
  109. Next
  110. If PosF = 0 Then PosF = 1
  111. GetFileName = Mid(FullPath, PosF)
  112. End Function
  113. Function BinaryToString(Binary)
  114. dim cl1, cl2, cl3, pl1, pl2, pl3
  115. Dim L
  116. cl1 = 1
  117. cl2 = 1
  118. cl3 = 1
  119. L = LenB(Binary)
  120. Do While cl1<=L
  121. pl3 = pl3 & Chr(AscB(MidB(Binary,cl1,1)))
  122. cl1 = cl1 + 1
  123. cl3 = cl3 + 1
  124. if cl3>300 then
  125. pl2 = pl2 & pl3
  126. pl3 = ""
  127. cl3 = 1
  128. cl2 = cl2 + 1
  129. if cl2>200 then
  130. pl1 = pl1 & pl2
  131. pl2 = ""
  132. cl2 = 1
  133. End If
  134. End If
  135. Loop
  136. BinaryToString = pl1 & pl2 & pl3
  137. End Function
  138. Function BinaryToStringold(Binary)
  139. Dim I, S
  140. For I = 1 To LenB(Binary)
  141. S = S & Chr(AscB(MidB(Binary, I, 1)))
  142. Next
  143. BinaryToString = S
  144. End Function
  145. Function StringToBinary(String)
  146. Dim I, B
  147. For I=1 to len(String)
  148. B = B & ChrB(Asc(Mid(String,I,1)))
  149. Next
  150. StringToBinary = B
  151. End Function
  152. Function vbsSaveAs(FileName, ByteArray)
  153. Dim FS, TextStream
  154. Set FS = CreateObject("Scripting.FileSystemObject")
  155. Set TextStream = FS.CreateTextFile(FileName)
  156. TextStream.Write BinaryToString(ByteArray) 
  157. TextStream.Close
  158. End Function
  159. </SCRIPT>
  160. <SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
  161. function CreateUploadField(){ return new uf_Init() }
  162. function uf_Init(){
  163. this.Name = null
  164. this.ContentDisposition = null
  165. this.FileName = null
  166. this.FilePath = null
  167. this.ContentType = null
  168. this.Value = null
  169. this.Length = null
  170. }
  171. function CreateBinaryData(){ return new bin_Init() }
  172. function bin_Init(){
  173. this.ByteArray = null
  174. this.Length = null
  175. this.String = jsBinaryToString
  176. this.SaveAs = jsSaveAs
  177. }
  178. function jsBinaryToString(){
  179. return BinaryToString(this.ByteArray)
  180. }
  181. function jsSaveAs(FileName){
  182. return vbsSaveAs(FileName, this.ByteArray)
  183. }
  184. </SCRIPT>
  185.